<?php

namespace app\api\controller;

use app\common\exception\BusinessException;
use think\response\Json;

class Promote extends Base
{

    /**
     * 首页信息
     * @return Json
     */
    public function info()
    {
        // 请求参数
        $param = $this->request->param();

        // 提交查询
        $response = (new \app\api\logic\Promote())->getInfo($param);

        // 返回
        return $this->response($response);
    }

    /**
     * 我的下级
     * @throws
     */
    public function mySubordinate(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'page' => 'require|number',
        ];

        // 错误信息
        $errMsg = [
            'page.require' => '页码page不得为空',
        ];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Promote())->mySubordinate($param);

        // 返回
        return $this->response($response);
    }

    /**
     * 成交订单
     * @throws
     */
    public function completedOrder(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'page' => 'require|number',
        ];

        // 错误信息
        $errMsg = [
            'page.require' => '页码page不得为空',
        ];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Promote())->completedOrder($param);

        // 返回
        return $this->response($response);
    }

    /**
     * 结算记录
     * @throws
     */
    public function settlementOrder(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'page' => 'require|number',
        ];

        // 错误信息
        $errMsg = [
            'page.require' => '页码page不得为空',
        ];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Promote())->settlementOrder($param);

        // 返回
        return $this->response($response);
    }

    /**
     * shareImage
     * @return Json
     * @throws
     */
    public function shareImage(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 查询数据
        $about = (new \app\api\logic\Promote())->shareImage($param);

        // 返回
        return $this->response($about);
    }
}
